DECLARE @xml XML

SET @xml = 
(
    SELECT
        SegmentId
    ,   [SegmentName]   = CAST('<![CDATA[' + ISNULL(SegmentName,'') + ']]>' AS xml)
    ,   SortOrdinal
    ,   CreateDate      = ISNULL(Core.dbo.fDateFormat(@GlobalDateFormat,CreateDate),'')
    ,   ParentSegmentId
    ,   ClientId
    ,   IsActive
    FROM
        Segment
    FOR XML AUTO, ELEMENTS, ROOT('Segments')
)

SELECT @xml
